 <?php
 
 class Model_m extends CI_Model
{
	 function __construct()
     {
        parent::__construct();
        $this->load->database();
			
		require_once dirname(__FILE__).'/wx/'.'lib/WxPay.Api.php';
		require_once dirname(__FILE__).'/wx/'.'WxPay.JsApiPay.php';
		require_once dirname(__FILE__).'/wx/'.'log.php';
			
     }
		
	 public function weixinnodify()
	 {   
		
		// 异步方法，没错 这个方法只是验证支付是否成功，也是demo中复制过来的~~
        ​require_once dirname(__FILE__).'/wx/'.'notify.php'; 
        ​$notify = new PayNotifyCallBack(); 
        ​$rs = $notify->Handle(false); 
        ​return $rs;
        
​	 }
	

	public function js_api_call($openId,$total_free,$out_trade_no)
	 {   
		//①、获取用户openid
		$tools = new JsApiPay();
		$openId = $tools->GetOpenid();
			
		//②、统一下单
		$input = new WxPayUnifiedOrder();
		$input->SetBody("test");
		$input->SetAttach("test");
		$input->SetOut_trade_no(WxPayConfig::MCHID.date("YmdHis"));
		$input->SetTotal_fee("1");
		$input->SetTime_start(date("YmdHis"));
		$input->SetTime_expire(date("YmdHis", time() + 600));
		$input->SetGoods_tag("test");
		$input->SetNotify_url("http://paysdk.weixin.qq.com/example/notify.php");
		$input->SetTrade_type("JSAPI");
		$input->SetOpenid($openId);
		
		$order = WxPayApi::unifiedOrder($input);
		$jsApiParameters = $tools->GetJsApiParameters($order);
		
		return $jsApiParameters;
		//获取共享收货地址js函数参数
		/* $editAddress = $tools->GetEditAddressParameters(); */
		

​	 }	
	  
}